import Fluent
import FluentPostgresDriver
import Vapor

// configures your application
public func configure(_ app: Application) throws {
    

    app.databases.use(.postgres(
        hostname: Environment.get("DATABASE_HOST") ?? "localhost",
        port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? 5432,
        username: Environment.get("DATABASE_USERNAME") ?? "icenter",
        password: Environment.get("DATABASE_PASSWORD") ?? "jRaHXw8iQ7mzY2sp",
        database: Environment.get("DATABASE_NAME") ?? "icenter_database"
    ), as: .psql)
    
//    app.databases.use(., as: .)

    app.migrations.add(CreateUser())
    app.migrations.add(CreateAdvancedBuilding())
    app.migrations.add(CreateProject())
    app.migrations.add(CreateSimpleBuilding())
    app.migrations.add(CreateMessage())
    app.migrations.add(CreateReference())
    app.migrations.add(CreateReferenceText())
    app.migrations.add(CreateReferenceVideo())
    app.migrations.add(CreateReferenceImage())
    app.migrations.add(CreateCountry())
    app.migrations.add(CreateLanguage())
    app.migrations.add(CreateEmployee())
    app.migrations.add(CreateEmployeeLanguagePivot())
    app.migrations.add(CreateEmployeeCountryPivot())
    app.migrations.add(CreateDepartment())
    app.migrations.add(CreateDepartmentEmployeePivot())

    app.logger.logLevel = .debug
    try app.autoMigrate().wait()
    // register routes
    try routes(app)
    
}
